/**
 * Created by SQB on 2015/6/3.
 */

$(function () {
    var titles = $('.notice-tit li');
    divs = $('.notice-con div');
    if (titles.length != divs.length) {
        return;
    }
    //遍历删除所有的li的select样式，然后再赋予
    var clicknotice = function () {
        var _this_ = $(this);
        titles.each(function () {
                if ($(this).hasClass('select')) {
                    $(this).removeClass('select');
                }
            }
        );
        _this_.addClass('select');
        divs.css({
            'display': 'none'
        });
        divs.eq(_this_.index()).css({
            'display': 'block'
        });
    }

    $('.notice li').click(clicknotice);

    var index =0;

    function triggerclick(i){
        titles.eq(i).trigger('click');
    }

    var timer = setInterval(function () {
        index++;
        if(index>=titles.length){
            index=0;
        }
        triggerclick(index);
    }, 3000);
    titles.hover(
        function(){
            var index1 = $(this).index();
            index=index1;
            clearInterval(timer)
            triggerclick(index);
        },
        function(){
            timer = setInterval(function(){
               index++;
                if(index>=titles.length){
                    index=0;
                }
                triggerclick(index);
            },3000);
        });
    //timer = setTimeout(clickfun,2000);
    triggerclick(0);

});